package com.irdstudio.apicenter.console.controller.template;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.alibaba.fastjson.JSON;
import com.irdstudio.apicenter.console.controller.MacmsBaseAction;
import com.irdstudio.apicenter.console.service.template.SPageParamMainService;

/**
 * app应用管理
 * 
 * @author jr
 * 
 */
@Controller
@RequestMapping(value = "/pageTemplateParam")
public class SPageParamMainAction extends MacmsBaseAction {
	@Autowired
	private SPageParamMainService sPageParamMainService;

	@RequestMapping(value = "savePageTemplateParam")
	public void savePageTemplateParam(HttpServletRequest request,
			HttpServletResponse response) throws SQLException,
			ClassNotFoundException, UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");//传值编码
		response.setContentType("text/html;charset=UTF-8");//设置传输编码
		int flag = -1;
		String recordKey = "";
		String paramvalue = "";
		if (request.getParameter("recordKey") != null) {
			recordKey = request.getParameter("recordKey");
		}
		if (request.getParameter("paramvalue") != null) {
			paramvalue = request.getParameter("paramvalue");
			/*paramvalue = java.net.URLDecoder.decode(request
					.getParameter("paramvalue"), "UTF-8");
			String paramvaluesd = new String(request.getParameter("paramvalue").getBytes("iso-8859-1"), "UTF-8");
			System.out.println(paramvaluesd+"----paramvalue=="+paramvalue);*/
		}
		
		flag = sPageParamMainService.update(recordKey, paramvalue);

		Map<String, Object> map = new HashMap<String, Object>(1);
		map.put("flag", flag);
		String jsonResult = JSON.toJSONString(map);
		PrintWriter printWriter = null;
		try {
			printWriter = response.getWriter();
			printWriter.print(jsonResult);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (null != printWriter) {
				printWriter.flush();
				printWriter.close();
			}
		}

	}

}
